import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  DeleteDateColumn,
  ManyToOne,
} from 'typeorm';
import { User } from './user';
import { Type } from './type';
import { DateTransformer } from '../utils/transformer';

@Entity()
export class Article {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  title: string;

  @Column({ type: 'text' })
  content: string;

  @Column()
  author: string;

  @Column()
  press: string;

  @Column()
  price: number;

  @Column()
  ISBN: string;

  @Column({ default: 1 })
  rate: number;

  @Column({ nullable: true })
  headPic: string;

  @Column({ nullable: true })
  tip: string;

  @Column({ nullable: true })
  sees: number;

  @Column({ comment: '是否官方消息 0不是 1是' })
  isOfficial: number;

  @ManyToOne(() => User, user => user.articles) // note: we will create author property in the Photo class below
  user: User;

  @ManyToOne(() => Type, type => type.articles) // note: we will create author property in the Photo class below
  type: Type;

  @CreateDateColumn({ transformer: new DateTransformer() })
  createDate;

  @UpdateDateColumn()
  updateDate;

  @DeleteDateColumn()
  deleteDate;
}
